import config from 'config'
import httpFetch from 'share/httpFetch'
import configureStore from 'stores';
import errorMessage from 'share/errorMessage';

export default {

  /**
   * 得到账本数据
   */
  getAccountBook(){
    let dashboardUserOID = configureStore.store.getState().login.user.userOID;
    return httpFetch.get(`${config.baseUrl}/api/dashboard/accountbook/${dashboardUserOID}`)
  },

  /**
   * 得到商务卡数据
   */
  getBusinessCard(){
    let dashboardUserOID = configureStore.store.getState().login.user.userOID;
    return httpFetch.get(`${config.baseUrl}/api/dashboard/personal/data/display/${dashboardUserOID}`)
  },

  /**
   * 得到待审批单据详情
   */
  getWaitForApprove(params){
    return httpFetch.get(`${config.baseUrl}/api/approvals/filters/count`, params)
  },

  /**
   * 得到单据动态
   */
  getLatestActive(page = 0, size = 5){
    return httpFetch.get(`${config.baseUrl}/api/approvals/latest`, { page, size })
  },

  /**
   * 得到待提报单据
   * @param page
   * @param size
   */
  getPendSubmitList(page, size){
    return httpFetch.get(`${config.baseUrl}/api/document/draft?size=${size}&page=${page}`)
  },

  /**
   * 得到企业各信息数量
   */
  getEnterpriseCount(){
    return httpFetch.post(`${config.baseUrl}/api/company/info/count`)
  },

  /**
   * 根据公司得到公告信息
   */
  getCarouselsByCompany(companyOID){
    return httpFetch.get(`${config.baseUrl}/api/carousels/company/${companyOID}`)
  },

  /**
   * 得到公告信息
   * @param params {enabled}是否可用
   */
  getCarousels(params){
    return httpFetch.get(`${config.baseUrl}/api/carousels/all`, params)
  },

  /**
   * 根据公司得到公告信息外部链接
   */
  getCarouselByID(carouselOID){
    return httpFetch.unsafe.get(`${config.baseUrl}/api/carousels/${carouselOID}`);
  },

  /**
   * 得到个人单据图表数据
   * @param year
   * @param month
   */
  getPersonalReportOverview(year, month){
    return httpFetch.get(`${config.baseUrl}/api/personal/expense/report/overview`, { year, month })
  },

  //获取欢迎，系统消息
  getSystemWelcomeInfo (channelCode) {
  return httpFetch.get(`${config.baseUrl}/notification/api/notification/message`)
    .catch(err => {
      errorMessage(err.response);
      throw err;
    })
},

  //消息修改已读状态接口
  alreadyRead () {
    return httpFetch.put(config.baseUrl + `/notification/api/notification/message/read`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  //获取待还款笔数以及总金额
  getWaitForPay() {
    return httpFetch.get(`${config.baseUrl}/api/loanBill/my/amountAndCount?statusList=1005&statusList=1006`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  //消息修改已读状态接口
  showCourse () {
    return httpFetch.get(config.baseUrl + `/api/operation/financecourse/tenantCheck`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  // 获取待提交的单据数据
  getToSubmitList(params){
    return httpFetch.get(`${config.baseUrl}/api/approvals/batchfilters/tosubmit`, params)
  },

  //查找用户授权状态
  getUserAuthorization() {
    let dashboardUserOID = configureStore.store.getState().login.user.userOID;
    return httpFetch.get(`${config.baseUrl}/api/user/authorization/findUserAuthorization?userOID=${dashboardUserOID}`)
  },

  //用户点击同意后，保存用户授权状态
  saveUserAuthorization() {
    let dashboardUserOID = configureStore.store.getState().login.user.userOID;
    return httpFetch.post(`${config.baseUrl}/api/user/authorization/saveUserAuthorization`, { userOID: dashboardUserOID})
  }
}
